訪問istio 內部負載平衡ip

前言

正文

要指定內部負載平衡IP的話,一般在svc上面是只要指定

metadata:
  annotations:
    cloud.google.com/load-balancer-type: "Internal"
spec:
    type: LoadBalancer    

這樣在GKE上面就會指定成內部負載平衡。
但在istio上面要指定的話,需在k8s底下新增 serviceAnnotations
像下面這樣(這是GKE的寫法,其他雲端機器設定的方式會不一樣)

k8s:
  serviceAnnotations:
    cloud.google.com/load-balancer-type: "Internal"

其他的參數請參考 istio安裝及使用 => 同一個叢集安裝多個ingressgateway

20.fig-1.jpg

ref.
Setup Multiple Ingress Gateways in Istio
How can I add service annotation in istio operator patch

VirtualService的寫法

Gateway的寫法與之前的一致,
比較有差異的是VS的寫法

hosts 需設定內部ip,不能使用 "*"
gateways 需增加mesh,表示路由是從網格內的流量來的。

如果不在gateways上面,寫mesh,會發生

503 upstream connect error or disconnect/reset before headers. reset reason local reset istio

的錯誤。
會發現這個錯誤,是因為看了Istio實踐避坑指南:10 大常見異常、最佳實踐及解決方案清楚網格內,與網格邊緣的差異,才知道增加此設定。

最後yaml如下

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: vs-internal
  namespace: default
spec:
  hosts:
    - 10.4.0.37
  gateways:
    - mesh
    - istio-ingressgateway-internal.default.svc.cluster.local
  http:
    - corsPolicy:
        allowOrigin:
          - '*'
      match:
        - uri:
            exact: /api/v1/health
      name: route-v1
      route:
        - destination:
            host: abc.default.svc.cluster.local
            port:
              number: 80
          weight: 100

ref.
Istio 運維實戰系列(3):讓人頭大的『無頭服務』-下
記一次Istio間歇503的問題排查